package com.wolfalpha.utron.service.impl;

import com.wolfalpha.utron.app.AppContext;
import com.wolfalpha.utron.net.URLs;
import com.wolfalpha.utron.service.FileService;
import com.wolfalpha.utron.utils.JsonUtils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by luodon on 15/9/1.
 */
public class FileServiceImpl implements FileService {

    @Override
    public String upload(File file) {
        Map<String, File> fmp = new HashMap<String, File>();
        fmp.put("upfile", file);
        String result = null;
        try {
            result = AppContext.getApiClient().uploadFile(URLs.FILE_URL + "upload", null, fmp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(result);
        if (JsonUtils.getRet(result) == 200) {
            return JsonUtils.getData(result);
        }
        return null;
    }

    @Override
    public String uploadBig(File file) {
        Map<String, File> fmp = new HashMap<String, File>();
        fmp.put("upfile", file);
        String result = null;
        try {
            result = AppContext.getApiClient().uploadFile(URLs.FILE_URL + "uploadBig", null, fmp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(result);
        if (JsonUtils.getRet(result) == 200) {
            return JsonUtils.getData(result);
        }
        return null;
    }
}
